setSelect();
function setSelect()
{
    var url = location.search; //获取url中"?"符后的字串
    var theRequest = new Object();
    if (url.indexOf("?") !== -1)
    {
        var str = url.substr(1);
        strs = str.split("&");
        for(var i = 0; i < strs.length; i ++) {
            theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
        }
    }
    console.log(theRequest["categoryId"]);
    document.getElementById(theRequest["categoryId"]).setAttribute("class","currentSelect");
}

var url = removeCom(); // 修改 URL 参数
history.replaceState(null, null, url);

function removeCom()
{
    console.log(par);
    var par = location.search;
    var pars = par.split("&");
    par = pars[0]+'&'+pars[1];
    console.log(par);
    return par;
}

var submit = document.getElementById("btn1");
var deletes = document.getElementsByClassName('delete');

submit.addEventListener('click',doSubmit)
for(var i = 0,l = deletes.length;i < l;i++)
{
    deletes[i].addEventListener('click',doDelete)
}

function doDelete()
{
    var told = confirm("是否删除评论？");
    if(told){
        var info = this.getAttribute("id");
        console.log(info);
        var infos = info.split('.');
        var comment = infos[0];
        comment = comment.substring(6)
        console.log(comment);
        var itemName = infos[1];
        itemName = itemName.substring(8);
        console.log(itemName);
        var username = infos[2];
        username = username.substring(8);
        console.log(username);

        $.ajax
        (
            {
                type:'GET',
                url:'http://localhost:8080/petstore/commentEdit?comment=' + comment + '&itemName=' + itemName,
                success: function (data)
                {
                    console.log("data"+data);
                    if(data == 1)
                    {
                        var row = document.getElementById("wrap"+comment+username)
                        console.log(row);
                        row.remove();
                        window.alert("删除成功！");
                    }
                    else
                    {
                        alert('删除失败');
                    }
                },
                error:function (errorMsg)
                {
                    console.log("fail");
                    console.log(errorMsg);
                    alert('删除失败');
                },
            }
        )
    }
    else ;



}


function doSubmit()
{
    var url = window.location.href;
    var com = document.getElementById("input").value;
    if(com === "")
    {
        alert("评论不能为空！")
        return;
    }
    console.log(com);
    location.href=url+'&COM='+com;
}